<template>
  <div class="sorts">
    <span @click="filterPersons(0) " ref="setcolor">综合排序</span>
    <span @click="filterPersons(1) " ref="setcolor">销量最多</span>
    <span @click="filterPersons(2) " ref="setcolor">评分最高</span>
    <div>
    <!-- {{filterPersons}} -->
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  data() {
    return {
      orderType: 0,
      
    };
  },
  computed: {
    ...mapState("Seller", ["sellerlistdata"]),
  },
  mounted(){
    this.filterPersons(0)
  },
    methods: {
    filterPersons(a) {
      // const { orderType, sellerlistdata } = this;
      let orderType = a
      let sellerlistdata = JSON.parse( localStorage.getItem('sellerlist') )
      // let sellerlistdata = this.sellerlistdata
      let fag;
      fag = sellerlistdata.filter(item=>item.name.indexOf(item.name) !== -1);
      
        fag.sort(function (p1, p2) {
          if (orderType === 1) {
            return p2.sales - p1.sales;
          }
          if(orderType === 2 ){
            return p2.wm_poi_score - p1.wm_poi_score;
          }
          if(orderType === 0 ){
            return p2.id - p1.id
          }
        });
      
      // console.log(fag)
      this.$store.dispatch('Seller/navsorts',fag)
      return fag 
    },
  },
};
</script>

<style lang='scss' scoped>
.sorts {
  height: 30px;
  width: 100%;
  display: flex;
  text-align: center;
  align-items: center;
  border-bottom: 0.5px solid #ccc;
  background: #FFCD5D;
  z-index: 100;
  div{
    display:none;
  }
  span {
    flex: 1;
    font-size: 14px;
    color: #666;
  }
  span:nth-of-type(2) {
    border-right: 1px solid #666;
    border-left: 1px solid #666;
  }
}
</style>